package message.rest;

import java.net.HttpURLConnection;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import javax.xml.bind.JAXBElement;
import session.web.PingSessionBean;
import utils.message.MessagePing;

@Path("/ping")
@Stateless
public class HandlePing {

    @Context
    UriInfo uriInfo;
    @Context
    Request request;
    @EJB
    PingSessionBean pingSessionBean;

    @POST
    @Consumes(MediaType.APPLICATION_XML)
    public Response handlePing(JAXBElement<MessagePing> jaxbMessage) {
        pingSessionBean.handlePing(jaxbMessage.getValue().getCurrentUser());
        return Response.status(HttpURLConnection.HTTP_ACCEPTED).entity("Ping message is received").build();
    }
}
